# _*_ coding : utf-8 _*_
# @Time : 2022/8/9 18:34
# @Author : Moonquake
# @File : 15.urllib异常
# @Project : python
import urllib.request
# url ='https://blog.csdn.net/sulixu/article/details/1198189491'
url ="http://"
headers={
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.81 Safari/537.36 Edg/104.0.1293.47'
}
try:
    request = urllib.request.Request(url=url,headers=headers)

    response = urllib.request.urlopen(request)

    content = response.read().decode('utf-8')

    print(content)

except urllib.error.HTTPError:
    print("HTTP错误")
except urllib.error.URLError:
    print("网址错误")